#Dice Rolls
#simple dice rolling app
#by john weddington
#version 1.3
#
#v1.1: managed to set up a structure for repeated rolls of the same dice in the
#> roll function.
#v1.2.1: Updated the interface and tested (all shiny.) but the printing of the results
#>had to be adjusted. and i finished the documentation aspect. It is now a
#>complete app.
#v1.2.2: PhearTheCeal did an awesome job on putting in exeptions to make 
#our drunk ass users can't screw things up to much.Kudos!
#v1.3: PhearTheCeal fixed a bug when the user entered a negative number

import random;

def roll(sides,rolls): #Function for the dice rolls 
    if sides == 0: #catch all for avoiding an error on the exit command.
        return 0;
    try:
        
        sides = int(sides);
        rolls = int(rolls);
    except TypeError:
        return 0
    result = 0;
    while rolls >> 0: #make sure that you roll the dice enough times
        result = random.randint(1,sides) + result;
        rolls = rolls - 1;
    return result;

print ("Dice Rolls\n Simple Dice Rolling App V.1.2.2\n by Brain-Bacon\n \n close app by typing 0 or a negative\n");
dice = 10;  #intialized variables beginning variables
amount = 1;
while dice != 0: #Primary loop for app
    dice = int(dice); 
    try:
        dice = int(input("enter number of sides to the dice: "));
        amount = int(input("enter number of dice to roll: "));
    except ValueError:
        print("\nYou did something wrong...\n")
        continue
    if dice < 1 or amount < 1: # exit if there is 0 or a negative number entered
        print("\n Thank you for using my app\n");
        exit()
    if amount == "": # default roll amounts
        amount = 1;
    amount = int(amount);
    print("Result of a ",str(dice)+"-sided die,",amount,"times is: ", roll(dice,amount), "\n")
    

    



